﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IIS
{
    public partial class PortForm : Form
    {
        public PortForm()
        {
            InitializeComponent();
        }

        private void PortForm_Load(object sender, EventArgs e)
        {
            this.txtPort.Text = "80";
            btnOk.DialogResult = DialogResult.OK;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string port = txtPort.Text.Trim();
            bool flag = IsNumeric(port);
            if (flag)
            {
                MainForm mf = (MainForm)this.Owner;
                mf.Port = int.Parse(port);
                this.Close();
            }
            else {
                MessageBox.Show("端口号填写错误！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            MainForm mf = (MainForm)this.Owner;
            mf.Port = 8080;
            this.Close();
        }

        static bool IsNumeric(string str)
        {
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"^[0-9]\d*$");
            return reg.IsMatch(str);
        }
    }
}
